package com.hsmw.schedule.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsmw.common.base.BaseService;
import com.htn.common.core.constant.ChildOrderStatusEnum;
import com.hsmw.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.hsmw.schedule.mapper.HsmwOrderVehicleRelationMapper;


import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class HsmwOrderVehicleRelationService extends BaseService<HsmwOrderVehicleRelationMapper, HsmwOrderVehicleRelation> {

	public boolean checkIfVehicleWorking(String vehicleId) {
		List<String> orderStatus = new ArrayList<>();
		orderStatus.add(ChildOrderStatusEnum.RECEIVED.getValue());
		orderStatus.add(ChildOrderStatusEnum.STARTUP.getValue());
		orderStatus.add(ChildOrderStatusEnum.ARRIVED.getValue());
		orderStatus.add(ChildOrderStatusEnum.WORKING.getValue());
		orderStatus.add(ChildOrderStatusEnum.UNDERREVIEW.getValue());
		List<HsmwOrderVehicleRelation> relations = this.list(new LambdaQueryWrapper<HsmwOrderVehicleRelation>().
				in(HsmwOrderVehicleRelation::getOrderStatus,orderStatus).
				eq(HsmwOrderVehicleRelation::getVehicleId,vehicleId));
		if(CollectionUtil.isNotEmpty(relations) && relations.size()>0){
			return false;
		}else {
			return true;
		}
	}

}
